package com.sl.biz.modular.ai.dao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.biz.modular.ai.dao.domain.entity.AiChatHistoryDO;
import com.sl.biz.modular.ai.dao.mapper.AiChatHistoryMapper;
import com.sl.biz.modular.ai.dao.service.AiChatHistoryDaoService;
import com.sl.common.page.CommonPageRequest;
import com.sl.common.page.PageList;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class AiChatHistoryDaoServiceImpl extends ServiceImpl<AiChatHistoryMapper, AiChatHistoryDO> implements AiChatHistoryDaoService {
    @Override
    public Boolean removeByAiId(String aiId) {
        LambdaQueryWrapper<AiChatHistoryDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(AiChatHistoryDO::getAiId, aiId);
        return super.remove(lambdaQueryWrapper);
    }

    @Override
    public List<AiChatHistoryDO> getByAiChatId(String aiChatId) {
        LambdaQueryWrapper<AiChatHistoryDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(AiChatHistoryDO::getAiChatId, aiChatId);
//        lambdaQueryWrapper.orderByDesc(AiChatHistoryDO::getStartTime);
//        lambdaQueryWrapper.
        return super.list(lambdaQueryWrapper);
    }

    @Override
    public List<AiChatHistoryDO> pageByAiChatId(String aiChatId, String userId) {
        LambdaQueryWrapper<AiChatHistoryDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(AiChatHistoryDO::getAiChatId, aiChatId);
        lambdaQueryWrapper.eq(AiChatHistoryDO::getUserId, userId);
        lambdaQueryWrapper.orderByDesc(AiChatHistoryDO::getStartTime);
        Page<AiChatHistoryDO> page = this.page(CommonPageRequest.defaultPage(), lambdaQueryWrapper);
        return PageList.valueOf(page);
    }

    @Override
    public Boolean removeByAiChatId(String aiChatId) {
        LambdaQueryWrapper<AiChatHistoryDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(AiChatHistoryDO::getAiChatId, aiChatId);
        return super.remove(lambdaQueryWrapper);
    }
}
